package com.haoan.index.service.impl;


import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.haoan.index.common.enums.ValiFlag;

import com.haoan.index.mapper.MessageMapper;
import com.haoan.index.domain.Message;
import com.haoan.index.service.MessageService;

/**
 * 留言咨询Service业务层处理
 *
 * @author autoGen
 * @date 2025-01-03
 */
@Service
public class MessageServiceImpl extends ServiceImpl<MessageMapper,Message> implements MessageService
{
    /**
     * 查询留言咨询
     *
     * @param id 留言咨询主键
     * @return 留言咨询
     */
    @Override
    public Message selectMessageById(Long id)
    {
        return baseMapper.selectById(id);
    }

    /**
     * 查询留言咨询列表
     *
     * @param message 留言咨询
     * @return 留言咨询
     */
    @Override
    public List<Message> selectMessageList(Message message)
    {
        LambdaQueryWrapper<Message> queryWrapper = new LambdaQueryWrapper<>();
        //todo 添加查询条件
        queryWrapper.eq(message.getId() != null, Message::getId, message.getId());
        queryWrapper.eq(message.getQuestion() != null, Message::getQuestion, message.getQuestion());
        queryWrapper.eq(message.getName() != null, Message::getName, message.getName());
        queryWrapper.eq(message.getPhone() != null, Message::getPhone, message.getPhone());

        queryWrapper.eq(message.getIsShow() != null, Message::getIsShow, message.getIsShow());
        queryWrapper.eq(message.getIsCommon() != null, Message::getIsCommon, message.getIsCommon());
        queryWrapper.eq(message.getCreateTime() != null, Message::getCreateTime, message.getCreateTime());
        queryWrapper.eq(message.getCreateBy() != null, Message::getCreateBy, message.getCreateBy());
        queryWrapper.eq(message.getUpdateTime() != null, Message::getUpdateTime, message.getUpdateTime());
        queryWrapper.eq(message.getUpdateBy() != null, Message::getUpdateBy, message.getUpdateBy());
        queryWrapper.eq(Message::getValiFlag,ValiFlag.VALID );

        return baseMapper.selectList(queryWrapper);
    }

    /**
     * 新增留言咨询
     *
     * @param message 留言咨询
     * @return 结果
     */
    @Transactional
    @Override
    public int insertMessage(Message message)
    {
        return baseMapper.insert(message);
    }

    /**
     * 修改留言咨询
     *
     * @param message 留言咨询
     * @return 结果
     */
    @Transactional
    @Override
    public int updateMessage(Message message)
    {
        return baseMapper.updateById(message);
    }

    /**
     * 批量删除留言咨询
     *
     * @param ids 需要删除的留言咨询主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteMessageByIds(Long [] ids)
    {
        Message message = new Message();
        message.setValiFlag(ValiFlag.INVALID);
        LambdaQueryWrapper<Message> updQw = new LambdaQueryWrapper<>();
        updQw.in(Message::getId, ids);
        return baseMapper.update(message, updQw);
    }

    /**
     * 删除留言咨询信息
     *
     * @param id 留言咨询主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteById(Long id)
    {
        Message message = getById(id);
        message.setValiFlag(ValiFlag.INVALID);
        return baseMapper.updateById(message);
    }
}
